﻿#ifndef UMENUBUTTON_H
#define UMENUBUTTON_H

#include "utkwidget_export.h"

#include <QPushButton>

class QMenu;
class QWidgetAction;
class QStandardItemModel;
class QStandardItem;
class UMenuButtonPrivate;
class UTKWIDGET_EXPORT UMenuButton : public QPushButton
{
    Q_OBJECT
public:
    explicit UMenuButton(QWidget* parent = nullptr);
    ~UMenuButton();

    QMenu* buttonMenu() const;

    QStandardItemModel* model() const;

    void addItems(QList<QStandardItem*> items);

    void addItem(QStandardItem* item);

    void clear();

    QStandardItem* actionItem(QAction* action);

public slots:
    void updateButtonContent(QAction* action);

protected:
    void paintEvent(QPaintEvent*) override;
    QSize sizeHint() const override;
    void resizeEvent(QResizeEvent *event) override;

signals:
    void triggered(QAction *action);

private:
    QScopedPointer<UMenuButtonPrivate> d_ptr;
    Q_DISABLE_COPY(UMenuButton)
    Q_DECLARE_PRIVATE_D(d_ptr, UMenuButton)
};

#endif // UMENUBUTTON_H
